require(['../config/requireconfig'],function(config){
	//根据需要添加
	require(['jquery','common/pccommons'],function($,com){
		
        com.init({headerPos:{menu:2,sub:1}});
		var pageLogic = new PageLogic($,com);
		pageLogic.init();

	});
});
var PageLogic = function($,com){
	return{
		init:function(){
			var _this = this;
			_this.initPartInfo();
		},
		initPartInfo:function(){
			var _this = this;
			com.ajax({
				url:"/partsCategoryInfos.json",
				success:function(res){
					_this.res = res.data;
					_this.displayInfos();
				}
			});
		},
		displayInfos:function(){
			var _this = this;
			var categoryid = com.utils().urlParam("categoryid");
			var html = "";
			$(_this.res).each(function(){
				var cls = "";
				if(!categoryid){
					if(html == ""){
						cls = "active";
						_this.categoryid = this.id;
					}
				}else{
					if(categoryid == this.id){
						cls = "active";
						_this.categoryid = this.id;
					}
				}
				html += '<li ' + (cls?"class='" + cls + "' ":'') + ' tg="' + this.id + '">' + this.categoryName + '<i class="blue-arrow"></i><div class="dot-line"></div></li>';
			});
			html += "<li class='split-line'></li>";
			$(".category-tab").html(html);
			_this.setCategoryTab();
			$(".category-tab").find("li").on("click",function(){
				$(".category-tab").find("li").removeClass("active");
				$(this).addClass("active");
				var tg = $(this).attr("tg");
				_this.categoryid = tg;
				_this.genContent();
			});
			_this.genContent();
		},
		genContent:function(){
			var _this = this;
			var html = "";
			$(_this.res).each(function(){
				if(this.id == _this.categoryid){
					$(this.parts).each(function(idx){
						var cls = "";
						if(idx%4 ==3){
							cls = "lst";
						}
						html += '<li tg="' + this.id + '" ' + (cls?("class='" + cls + "'"):'') + '><img src="' + (com._Options.domain + this.imageUrl) + '"><p>' + this.partsName + '</p></li>';
					});
				}
			});
			$(".category-list").html(html);
			
			$(".category-list").find("li").on("click",function(){
				location.href="/prodCategoryDetail.htm?partsInfoId=" + $(this).attr("tg");
			});
		},
		setCategoryTab:function(){
			var width = $(".container").width();
			var allLiWidth = 0;
			$(".category-tab").find("li").each(function(){
				allLiWidth += $(this).width();
			});
			var space = (width - allLiWidth -20)/10;
			$(".category-tab").find("li").each(function(idx){
				if(idx < 10){
					$(this).css({"margin-right":space});
				}else{
					$(this).css({"margin-right":0});
				}
			});
		},
	}
}